package com.module.record.controller;

import com.module.common.annotation.Log;
import com.module.common.core.controller.BaseController;
import com.module.common.core.domain.AjaxResult;
import com.module.common.core.page.TableDataInfo;
import com.module.common.enums.BusinessType;
import com.module.common.utils.DateUtils;
import com.module.common.utils.poi.ExcelUtil;
import com.module.record.domain.vo.RecordOnlineVO;
import com.module.record.service.IRecordOnlineService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 设备上下线Controller
 *
 */
@Controller
@RequestMapping("/record/online")
public class RecordOnlineController extends BaseController {

    private String prefix = "record/online";

    @Autowired
    private IRecordOnlineService recordOnlineService;

    @RequiresPermissions("record:online:view")
    @GetMapping()
    public String online(ModelMap mmap)
    {
        mmap.put("startDate", DateUtils.getMonth() + "-01");
        mmap.put("endDate", DateUtils.getDate());
        return prefix + "/online";
    }

    /**
     * 查询采集设备列表
     */
    @RequiresPermissions("record:online:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordOnlineVO recordOnlineVO)
    {
        List<RecordOnlineVO> list = recordOnlineService.selectRecordOnlineList(recordOnlineVO);
        return getDataTable(list);
    }

    /**
     * 清理上下线记录
     * @param recordOnlineVO
     * @return
     */
    @Log(title = "上下线记录", businessType = BusinessType.EXPORT)
    @RequiresPermissions("record:online:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordOnlineVO recordOnlineVO)
    {
        List<RecordOnlineVO> list = recordOnlineService.selectRecordOnlineList(recordOnlineVO);
        ExcelUtil<RecordOnlineVO> util = new ExcelUtil<RecordOnlineVO>(RecordOnlineVO.class);
        return util.exportExcel(list, "上下线记录");
    }

    /**
     * 清理上下线记录
     * @return
     */
    @RequiresPermissions("record:online:clean")
    @Log(title = "上下线记录", businessType = BusinessType.CLEAN)
    @PostMapping("/clean")
    @ResponseBody
    public AjaxResult clean()
    {
        recordOnlineService.cleanRecordOnline();
        return success();
    }
}
